package com.zhuang.designpattern.factory.optimize;

import com.zhuang.designpattern.factory.optimize.impl.CardCommodityService;
import com.zhuang.designpattern.factory.optimize.impl.CouponCommodityService;
import com.zhuang.designpattern.factory.optimize.impl.GoodsCommodityService;

/**
 * description: StoreFactory
 * date: 2022/9/10 11:12
 * author: Zhuang
 * version: 1.0
 */
public class StoreFactory {
    /**
     * 根据传入的类型判断返回什么商品的优惠服务
     *
     * @param commodityType Integer
     * @return ICommodity
     */
    public ICommodity getCommodityService(Integer commodityType) {
        if (null == commodityType) return null;
        if (1 == commodityType) return new CouponCommodityService();
        if (2 == commodityType) return new GoodsCommodityService();
        if (3 == commodityType) return new CardCommodityService();
        throw new RuntimeException("不存在的商品服务类型");
    }
}
